package com.itec.learn.java.design.singleton.doublecheck;

/**
 * 双重检查加锁- double-checked locking
 * 这种写法依然可能存在问题，不能保证instance初始化后被所有线程可见，需要使用volatile关键字
 */
public class DoubleCheck {
    private static Object lock = new Object();
    private static DoubleCheck instance = null;

    private DoubleCheck(){

    }

    public static DoubleCheck getInstance(){
        if (instance == null){
            synchronized (lock){
                if (instance == null){
                    instance = new DoubleCheck();
                }
            }
        }
        return instance;
    }
}
